package be.phl.android.project;

import persist.Activiteit;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

public class LessenroosterActivity extends Activity {
	private TextView tv;

	private void loadData() throws Exception {
		Activiteit[][] lessenrooster = null;
		String output = "";
		JsonHandler handler = JsonHandler.getInstance();
		lessenrooster = handler.getLessenrooster();
		if (lessenrooster == null)
			throw new Exception(
					"Geen lessenrooster gevonden! Probeer te updaten of later opnieuw!");
		for (int i = 0; i < lessenrooster.length; i++) {
			if (lessenrooster[i].length > 0) {
				switch (i) {
				case 0:
					output += "Maandag \n ---------------------------\n";
					break;
				case 1:
					output += "Dinsdag \n ---------------------------\n";
					break;
				case 2:
					output += "Woensdag \n ---------------------------\n";
					break;
				case 3:
					output += "Donderdag \n ---------------------------\n";
					break;
				case 4:
					output += "Vrijdag \n ---------------------------\n";
					break;
				case 5:
					output += "Zaterdag \n ---------------------------\n";
					break;
				}
				for (int j = 0; j < lessenrooster[i].length; j++) {
					output += lessenrooster[i][j].toString() + "\n\n";
				}
				output += "---------------------------\n";
			}
		}
		tv.setText(output);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		try {
			// TODO Auto-generated method stub
			super.onCreate(savedInstanceState);
			setContentView(R.layout.overzicht);

			tv = (TextView) findViewById(R.id.overzicht);
			loadData();
			tv.setMovementMethod(new ScrollingMovementMethod());
		} catch (Exception e) {
			// Toast.makeText(getApplicationContext(),
			// e.toString(),Toast.LENGTH_LONG);
			finish();
		}
	}

	@Override
	protected void onRestart() {
		try {
			super.onRestart();
			loadData();
		} catch (Exception e) {
			// Toast.makeText(getApplicationContext(),
			// e.toString(),Toast.LENGTH_LONG);
			finish();
		}
	}
}
